package cn.itrip.biz.controller;

import cn.itrip.biz.service.itripHotelRoom.ItripHotelRoomService;
import cn.itrip.biz.service.itripImage.ItripImageService;
import cn.itrip.biz.service.itripLabelDic.ItripLabelDicService;
import cn.itrip.common.DtoUtil;
import cn.itrip.common.EmptyUtils;
import cn.itrip.dto.Dto;
import cn.itrip.pojo.ItripHotelRoom;
import cn.itrip.pojo.ItripImage;
import cn.itrip.pojo.ItripLabelDic;
import cn.itrip.vo.ItripImageVO;
import cn.itrip.vo.ItripLabelDicVO;
import cn.itrip.vo.hotelroom.ItripHotelRoomVO;
import cn.itrip.vo.hotelroom.SearchHotelRoomVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@RestController  //Controller+responseBody
@RequestMapping(value = "/api/hotelroom")
@Api(value = "biz测试HotelRoomController", tags = "{biz测试HotelRoomController}")
public class HotelRoomController {

    @Resource
    private ItripHotelRoomService itripHotelRoomService;
    @Resource
    private ItripImageService itripImageService;



    @ApiOperation(value = "查询酒店房间")
    @RequestMapping(value = "/queryhotelroombyhotel", method = RequestMethod.POST, produces = "application/json")
    public Dto<List<List<ItripHotelRoomVO>>> queryHotelRoomByHotel(@RequestBody SearchHotelRoomVO vo) {
        try {
            if (vo.getHotelId()==null && vo.getEndDate()==null){
                return DtoUtil.returnFail(" 酒店id不能为空,酒店入住及退房时间不能为空,入住时间不能大于退房时间", "100303");
            }

            //返回的数据
            List<ItripHotelRoom> hotelRoomList = itripHotelRoomService.getItripHotelRoomListById(vo);

            //封装前端需要的实体类
            List<List<ItripHotelRoomVO>> hotelRoomListList=new ArrayList<List<ItripHotelRoomVO>>();

            for (ItripHotelRoom room : hotelRoomList) {
                List<ItripHotelRoomVO> itripHotelRoomVOS=new ArrayList<>();
                ItripHotelRoomVO roomVo=new ItripHotelRoomVO();

                roomVo.setId(room.getId());
                roomVo.setHotelId(room.getHotelId());
                roomVo.setIsBook(room.getIsBook());
                roomVo.setIsCancel(room.getIsCancel());
                roomVo.setIsHavingBreakfast(room.getIsHavingBreakfast());
                roomVo.setIsTimelyResponse(room.getIsTimelyResponse());
                roomVo.setPayType(room.getPayType());
                roomVo.setRoomBedTypeId(room.getRoomBedTypeId());
                roomVo.setRoomPrice(BigDecimal.valueOf(room.getRoomPrice()));
                roomVo.setRoomTitle(room.getRoomTitle());
                roomVo.setSatisfaction(Double.valueOf(room.getSatisfaction()));

                itripHotelRoomVOS.add(roomVo);
                hotelRoomListList.add(itripHotelRoomVOS);
            }
            return DtoUtil.returnDataSuccess(hotelRoomListList);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常", "100304");
        }
    }


    @ApiOperation(value = "查询酒店房间床型列表")
    @RequestMapping(value = "/queryhotelroombed", method = RequestMethod.GET, produces = "application/json")
    public Dto<List<ItripLabelDic>>  queryHotelRoombed(){
        try {
            List<ItripLabelDicVO> dics = itripHotelRoomService.getItripHotelRoomByBookList();
            return DtoUtil.returnDataSuccess(dics);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常", "10204 ");
        }
    }

    @ApiOperation(value = "根据targetId查询酒店房型图片(type=1)")
    @RequestMapping(value = "/getimg/{targetId}", method = RequestMethod.GET, produces = "application/json")
    public Dto<List<ItripLabelDic>>  getImg(@PathVariable String targetId){
        try {
            List<ItripImageVO> dics = itripImageService.getImgTargetId(targetId);
            System.out.println(dics);
            return DtoUtil.returnDataSuccess(dics);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常", "10204 ");
        }
    }
}
